<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var jump = function (nums) {
      let end = 0,
        longest = 0,
        count = 0;
      for (let i = 0; i < nums.length - 1; i++) {
        // 注意此处设定为i<length-1
        // 根据题目要求，假定每一个组合都能够跳到最终位置，因此最后一个位置不需要计算在内
        longest = Math.max(longest, nums[i] + i);
        if (end === i) {
          count++;
          end = longest;
        }
      }
      return count;
    };
    console.log(jump([2, 3, 1, 1, 4]));
  </script>
</body>

</html>